package com.leeon.exception.exmaples;


import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

class LoggerException1 extends Exception{

    private static Logger logger = Logger.getLogger("LoggerException1");

    public LoggerException1(){
        StringWriter trace = new StringWriter();
        printStackTrace(new PrintWriter(trace));
        logger.severe(trace.toString());
    }

}

class LoggerException2 extends Exception{

    private static Logger logger = Logger.getLogger("LoggerException2");

    public LoggerException2(){
        StringWriter trace = new StringWriter();
        printStackTrace(new PrintWriter(trace));
        logger.severe(trace.toString());
    }

    public LoggerException2(String msg){
        super(msg);
        StringWriter trace = new StringWriter();
        printStackTrace(new PrintWriter(trace));
        logger.severe(trace.toString() + msg);
    }
}

public class Exmaple6{

    public static void main(String[] args) {
        try {
            throw new LoggerException1();
        }catch (LoggerException1 e){

        }

        try {
            throw  new LoggerException2();
        }catch (LoggerException2 e){

        }
    }
}
